<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--suppress ALL -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>采购询价</title>
<link href="/res/css/respective/priceAsk/buyer.css" rel="stylesheet">
<link href="/res/third/city-picker/css/city-picker.css" rel="stylesheet">
	<style>
.backcontent .backfoot {
	padding-left: 0px;
}
.city-picker-span{
	min-width: 215px;
    height: 32px;
    line-height: 31px;
    border: 1px solid #e9e9e9;
    padding-left: 15px;
    display: inline-block;
}
.toUpBill{
	color: #00b1db;position: absolute;right: 0;top:-50px;
}
.toUpBill:hover{
color: #1a8df3;}
#phoneTip span[role="alert"]{
    line-height: 19px;
}

#phoneTip span.n-icon{
    margin-top: 1.5px;
}


</style>
</head>
<body>
	[#include "/front/common/front_head.html"]
	<div class="warp" style="margin-top: 30px;">
		<div class="backcontent">
			<div class="back-main">
				<div class="mainContent" style="box-shadow:none;-moz-box-shadow:none;">
					<img src="/res/images/priceAsk/chosePublic.png" alt=""
						style="width: 100%; margin-top: 47px;" />
					<div class="createOp">
						<h1>发布采购询价</h1>
						<form type="post" id="subform" autocomplete="off" >
							<input type="hidden" value="2" name="qtype" />
							<div class="juZhong">
								<div style="padding: 35px 70px;background: white;">

							[#if !user??]
								<input type="hidden" name="temporary" value="true" />
                                <div class="secTitle">
                                    <span>您还未登录，为了方便您发布询价，点击</span> <a href="javascript:login();">登录</a>/
                                    <a href="/user/register" target="_blank" >注册 </a>
                                </div>
							[#else ]
								<input name="enqProject.customerId" value="${user.companyId!}" type="hidden" />
								<input name="enqProject.userId" value="${user.id}" type="hidden" />
								<input type="hidden" value="${user.id}" name="userId" />
								<input type="hidden" value="${(enqmodel.id)!}" name="id"  />

							[/#if]
								<h2 class="thirdTitle">询价单名称</h2>
								<hr>
								<span>*</span>
								<input type="text" name="enquiryName"
                                [#if editor??]
                                       readonly
                                [/#if]
                                       style="width: 580px;"  value="${(enqmodel.enquiryName)!}" placeholder="请为该询价单写一个名称，方便您查阅。如：电缆询价第10单"/>

							[#--选择的推荐供应商,如果有推荐供应商,就是非公开发布,否则是公开发布--]
							[#if recod?? && recod.ids?? ]
								<input type="hidden" name="pubtype" value="2" />
					            <h2 class="thirdTitle">已选择供应商 </h2>
								<hr>
					            <div>
					                <input type="hidden" value="${inviteCids!}" name="inviteCids" />
					                <input type="hidden" value="${inviteTels!}" name="inviteTels" />
					                [#--不公开发布选择的供应商--]
					                [#list recod.names as recommend ]
					                	<div style="display:inline-block;">
							            	<dfn class="delSuply"><small style="margin-right: auto;"> ${recommend!}</small></dfn>
							            </div>
					                [/#list]
					            </div>
							[#else ]
                                <input type="hidden" name="pubtype" value="1" />
					        [/#if]
					        	<h2 class="thirdTitle">询价清单</h2>
								<hr>

								[#--无用字段,辅助验证用的 --]
								<input id="excelvalid" type="hidden" value="[#if ((enqmodel.items)?? && enqmodel.items?size > 0 ) || (enqmodel.excelpath)?? ]1[#else]0[/#if]" name="excelvalid" />

                                [#--有items 或者 有excelpath 时 该项隐藏--]
                                <div id="upbefore" class="imgYalign"
								[#if ((enqmodel.items)?? && enqmodel.items?size > 0 )||(enqmodel.excelpath)??  ]
                                     style="display: none;"
								[/#if]
                                >
                                    <div>
                                        <h1>请上传询价清单</h1>
                                        <h2>建议使用Excel格式上传，方便系统为您更精准的推送给合适的供应商。</h2>
                                        <button type="button" onclick="uploadfile()" style="width: 125px;height: 30px;">上传清单</button>
                                        <a  href="/res/excel/询价模板.xls" target="_blank" >下载询价模板</a>
                                        <a onclick="addbyhand()">询价产品太少？点此手动填写</a>
                                    </div>
                                </div>



                                [#--有excelpath,且 items 为空时 显示重新上传--]
								<div id="switchDiv" class="switchDiv"
				                [#if (!(enqmodel.excelpath)??) || (((enqmodel.items)??) && (enqmodel.items?size > 0)) ]
				                     style="display: none"
				                [/#if]
				                >
				                <a style="position: absolute;top:-50px;right: 0px;color: #00a8e6;" onclick="toHandOp()">询价产品太少？点此手动填写</a>
									<p style="font-size: 12px;margin-bottom: 10px;">请在运营人员通过审核后查询匹配结果</p>
				                    <input type="hidden" name="excelpath" id="excelpath" value="${(enqmodel.excelpath)!}"   />
				                    <input type="hidden" name="excelName" id="excelName" value="${(enqmodel.excelName)!}" />
				                    <a id="filename" target="_blank" href="${(enqmodel.excelpath)!}" >[#if enqmodel?? && enqmodel.excelName?? && enqmodel.excelName!=""]${(enqmodel.excelName)!}[#else]${(enqmodel.excelpath)!}[/#if]</a>
                                    &nbsp;&nbsp;<a id="delurl" onclick="delurl()">删除</a>
                                    <button class="reUp" type="button" onclick="uploadfile()">重新上传</button>
									[#if !editor?? ]
									[#--<a class="reUp" href="javascript:void(0)" onclick="analysis()">我要自己解析清单</a>--]
									[/#if]
				                </div>



				                <div style="position: relative;">
				                <div id="upbyhand"
				                [#if (!(enqmodel.items)??) || (enqmodel.items?size < 1) ]
				                     style="display: none;"
				                [/#if]
				                >
				               <a class="toUpBill" onclick="toUp()">询价产品很多？点此上传</a>
				                    <table class="table noBorder smallTable" style="width: 100%;">
				                        <thead>
				                        <tr class="handHead">
				                            <th>所属系统</th>
				                            <th><dfn><span>*</span>商品名称</dfn></th>
				                            <th><dfn>品牌</dfn> </th>
				                            <th><dfn>型号</dfn></th>
				                            <th><dfn><span>*</span>单位 </dfn></th>
				                            <th><dfn><span>*</span>数量</dfn></th>
				                            <th><dfn>技术参数</dfn></th>
				                            <th><a class="delAll" onclick="deleall(true)">全部删除</a></th>
				                        </tr>
				                        </thead>
				                        <tbody id="handBody">
				                        	[#if (enqmodel.items)??  && (enqmodel.items?size > 0 )]
												[#list enqmodel.items as item ]
												<tr attindex="${item_index}" >
													<td>
                                                        <button class="choseOpButt" type="button"  onclick="chooseService(this)"     >
														[#--老数据导入后,有的没有第三级id--]
															[#if item.categoryPId?? ]
															${item.categorySName!"选择系统"}
															[#else]
                                                                选择系统
															[/#if]
														</button>
                                                        <input  type="hidden" value="${item.categorySId!}"  class="categorySId" name="items[${item_index}].categorySId" />
                                                        <input  type="hidden" value="${item.categoryPId!}" class="categoryPId" name="items[${item_index}].categoryPId" />
													</td>
													<td>
														<dfn id="delCont" style="position: relative;">
															<input  type="text" novalidate name="items[${item_index}].productName" value="${item.productName}"  class="input_1 ainput" />
															<a class="delCont">×</a>
														</dfn>
													</td>
													<td><dfn><input type="text"  novalidate name="items[${item_index}].brand"  value="${item.brand!}" class="ainput"  /></dfn></td>
													<td><dfn><input type="text"  novalidate name="items[${item_index}].model" value="${item.model!}"  class="ainput" /></dfn></td>
													<td><dfn><input type="text"  novalidate name="items[${item_index}].unit"   value="${item.unit!}"  class="input_4 ainput" /></dfn></td>
													<td><dfn><input type="text"  novalidate name="items[${item_index}].quantity"  value="${item.quantity!}" class="input_5 ainput"  /></dfn></td>
													<td><dfn><input type="text"  novalidate name="items[${item_index}].descr" value="${item.descr!}" class="ainput"  /></dfn></td>
													<td class="del" onclick="deletetr(this)" style="cursor: pointer;" ></td>
												</tr>
												[/#list]
				                        	[#else ]
                                                <tr attindex="0" >
                                                    <td>
                                                        <button  class="choseOpButt" type="button"  onclick="chooseService(this)">选择系统</button>
                                                        <input type="hidden" value="" name="items[0].categorySId" class="categorySId" />
                                                        <input type="hidden" value="" name="items[0].categoryPId" class="categoryPId"  />
                                                    </td>
                                                    <td>
                                                        <dfn id="delCont" style="position: relative;">
                                                            <input  type="text" novalidate name="items[0].productName" class="input_1 ainput" />
                                                            <a class="delCont">×</a>
                                                        </dfn>
                                                    </td>
                                                    <td><dfn><input type="text"  novalidate name="items[0].brand" class="ainput"  /></dfn></td>
                                                    <td><dfn><input type="text"  novalidate name="items[0].model" class="ainput"  /></dfn></td>
                                                    <td><dfn><input type="text"  novalidate name="items[0].unit"     class="input_4 ainput" /></dfn></td>
                                                    <td><dfn><input type="text"  novalidate name="items[0].quantity" class="input_5 ainput"  /></dfn></td>
                                                    <td><dfn><input type="text"  novalidate name="items[0].descr" class="ainput"  /></dfn></td>
                                                    <td class="del" onclick="deletetr(this)" style="cursor: pointer;" ></td>
                                                </tr>
				                         [/#if]
				                        </tbody>
				                        <tfoot>
				                        <tr class="tableBorde" style="background: none;">
				                            <td colspan="8" style="text-align: right;padding:15px;">
				                                <button  onclick="additem()"  type="button" class="addProduc">新增产品</button>
				                            </td>
				                        </tr>
				                        </tfoot>
				                    </table>
				                	</div>
				                </div>
				                <h2 class="thirdTitle">询价要求</h2>
				                <hr>
				                <div class="lableIterm">
					                <label><span>*</span>报价截止时间：</label>
					                <input  id="endtime" data-rule="截止时间:required;"   value="${(enqmodel.deadline?string("yyyy-MM-dd"))!}" name="deadline"   type="text" class="clock"/>
					            </div>
					            <div class="lableIterm">

					                <label><span>*</span>质保要求：</label>
									[#--新打开页面时,默认选中第一个--]
					                <input style="margin-left: 0px" type="radio" name="quality" value="1"  [#if !enqmodel??]checked="checked"[/#if][#if !(enqmodel.quality)??]checked="checked"[/#if][#if (enqmodel.quality)?? && enqmodel.quality==1 ]checked="checked"[/#if]  />1年

					                <input type="radio" name="quality" value="2" [#if (enqmodel.quality)?? && enqmodel.quality==2 ] checked="checked" [/#if]>2年


					                <input type="radio" name="quality" value="3" [#if (enqmodel.quality)?? && enqmodel.quality==3 ] checked="checked" [/#if]>3年


					                 <input type="radio" name="quality" value="15" [#if (enqmodel.quality)?? && enqmodel.quality==15 ] checked="checked" [/#if]>15年


					                 <input type="radio" name="quality" value="-1"
											[#if (enqmodel.guaranteeinfo)?? && (  (!enqmodel.quality??) || (enqmodel.quality?? && enqmodel.quality==-1))  ]checked="checked" [/#if]
									 >其他
					                 <input  name="guaranteeinfo" id="guaranteeinfo" value="[#if (enqmodel.guaranteeinfo)??   ]${enqmodel.guaranteeinfo!}[/#if]"  type="text" style="width: 80px;height: 20px;margin-left: 15px;
									 [#--有特殊质保要求时,该input显示--]
									 [#if (enqmodel.guaranteeinfo)?? && (  (!enqmodel.quality??) || (enqmodel.quality?? && enqmodel.quality==-1))  ][#else]display:none;[/#if] " />

					            </div>
					            <div class="lableIterm">
					                <label>报价要求：</label>
					                <input type="checkbox"  name="taxPrice" id="taxPrice" value="1"
					                    [#if (enqmodel.taxPrice)?? && enqmodel.taxPrice!=3 ]
					                        checked="checked"
					                    [/#if]
					                    >包含税价
					                <div class="form-controlAzt ppSelect dealSelec" id="taxInstro"
										[#if (enqmodel.taxPrice)?? && enqmodel.taxPrice!=3 ]
										[#else]
                                        style="display: none;"
										[/#if]
									>
									[@m.select  name="taxInstro" options={"3":"3%","6":"6%","17":"17%"} val=((enqmodel.taxInstro)!17)?string  attr="style='height: 100%; border: none;'"  /]
					                </div>

					                <label style="width: auto;">
					                    <input style="margin-left: 10px;" type="checkbox" value="1" name="shipPrice"
					                    [#if  (enqmodel.shipPrice)?? && enqmodel.shipPrice==1]
					                    checked="checked"
					                    [/#if]
					                    >包含运费价
					                </label>
            					</div>


                                <div class="lableIterm">
                                    <label class="col-xs-2 control-label"><span>*</span>支付方式：</label>
                                        <input style="margin-left: 0px;" type="radio" name="payment" value="1"
										[#if !((enqmodel.payment)??)]checked="checked"[/#if]
										[#if (enqmodel.payment)?? && enqmodel.payment==1 ]
                                               checked="checked"
										[/#if]

                                        >款到发货
                                        <input type="radio" name="payment" value="2"
										[#if (enqmodel.payment)?? && enqmodel.payment==2 ]
                                               checked="checked"
										[/#if]
                                        >货到付款
                                        <input id="fenpi" type="radio" name="payment"  value="3"
										[#if (enqmodel.payment)?? && enqmodel.payment==3 ]
                                               checked="checked"
										[/#if]
                                        >分期付款
										<span id="msgbox" ></span>
                                    	<input type="hidden" value="${(enqmodel.batchPay)!}"  name="batchPay" id="batchPay"  />
										<div id="zhifufangshi"   [#if enqmodel?? && enqmodel.batchPay?? && enqmodel.batchPay!="" ][#else]style="display: none;"[/#if] >
											<div class="fqOuter">
												[#if (enqmodel.batchList)??]
													[#list enqmodel.batchList as b ]
														[#if b_index == 0]
                                                            <div class="fqpc">
                                                                <em class="ppSelect bfb fqs ">第1期</em>
                                                                <input class="ppSelect bfb" name="pici" value="${b.per!}" placeholder="百分比" type="text"/>
                                                                <input class="ppSelect bz" name="beizhu" value="${b.remark!}"  maxlength="50" placeholder="备注：如订金、货到两天内等（50字）" type="text"/>
                                                            </div>
														[#else]
                                                            <div class="fqpc">
                                                                <em class="ppSelect bfb fqs piciindex">第${b.no+1}期</em>
                                                                <input class="ppSelect bfb" name="pici" value="${b.per!}" placeholder="百分比" type="text"/>
                                                                <input class="ppSelect bz" name="beizhu" value="${b.remark!}" maxlength="50" placeholder="备注：如订金、货到两天内等（50字）" type="text"/>
                                                                <a style="vertical-align: middle;" onclick="cancleFq(this)">取消</a>
                                                            </div>
														[/#if]
													[/#list]
												[#else]
                                                    <div class="fqpc">
                                                        <em class="ppSelect bfb fqs ">第1期</em>
                                                        <input class="ppSelect bfb" name="pici" placeholder="百分比" type="text"/>
                                                        <input class="ppSelect bz" name="beizhu" maxlength="50" placeholder="备注：如订金、货到两天内等（50字）" type="text"/>
                                                    </div>
												[/#if]
											</div>

											<div style="margin-left: 120px;margin-top: 15px;">
												<em style="margin-right: 5px;">+</em><a onclick="addpici()">增加付款批次</a><em>（最多设置6期）</em>
											</div>
										</div>
                                </div>
                                <div class="lableIterm">
                                    <label>补充说明：</label>
                                    <textarea style="vertical-align: top;" name="otherRemarks" rows="5" cols="95" class="form-control" aria-required="true">${(enqmodel.otherRemarks)!}</textarea>


									[#--附件结果--]
                                    <input type="hidden" name="attachfile" id="attachfile"
                                           value="${(enqmodel.attachfile)!}"
                                    />
                                    <input type="hidden" name="attachfileName" id="attachfileName"
                                           value="${(enqmodel.attachfileName)!}"
                                    />

									<div class="lableIterm" id="uploadattach"
									[#if (enqmodel.attachfile)?? && enqmodel.attachfile!="" ]
                                         style="display: none"
									[/#if]
									>
                                        <label></label>
                                        <img alt="" src="/res/images/priceAsk/ask04.png" style="vertical-align: middle;">
                                        <a id="fileUpload" style="font-size: 14px;color: #00b1db;vertical-align: middle;padding: 6px;"
                                           onclick="uploadEnclosure()"
                                        >添加附件</a>
                                    </div>
                                    <div id="uploadattachfile" class="switchDiv col-xs-8"
									[#if !((enqmodel.attachfile)?? && enqmodel.attachfile!="") ]
                                         style="display: none;"
									[/#if]
                                    >
                                        <a id="attachfileNameTip" style="margin-left: 120px;" href="${(enqmodel.attachfile)!}" target="_blank" >[#if enqmodel?? && enqmodel.attachfileName??]${(enqmodel.attachfileName)!}[#else]${(enqmodel.attachfile)!}[/#if]</a>
                                        &nbsp;&nbsp;<a   onclick="delattachurl()"  style="color: #00a8e6;">删除</a>
                                        <button class="reUp" type="button" style="padding: 6px;" onclick="uploadEnclosure()">重新上传</button>
                                    </div>
                                </div>
                                <h2 class="thirdTitle">项目信息</h2>
								<hr>
                                <div class="lableIterm">
                                    <label ><span>*</span>项目名称：</label>

								[#if editor?? ]
                                    <input name="projectId" value="${enqmodel.projectId}" type="hidden"  >
								[#else]
								[#--编辑状态不用显示项目名称输入框--]
                                    <input  id="choosenew"     name="enqProject.projectName"  value="${(enqmodel.enqProject.projectName)!}"   type="text" class="form-control" placeholder="供应商能查看，建议输入内容不包含甲方名称。如：某净化工程项目"/>
								[/#if]

								[#--选择已经有的之后,这里显示选择的项目名称--]
								[#if editor?? ]
                                    <a id="chhoseold" style="color: black;text-decoration: none;" >${enqmodel.enqProject.projectName}</a>
								[#else]
                                    <a id="chhoseold" style="color: black;display: none;text-decoration: none;" ></a>
								[/#if]


								[#if !editor?? ]
									[#--编辑状态,不显示该按钮--]
                                    <a  id="createnew" style="color: #00b1db;display: none" >创建新的?</a>
								[/#if]

								[#if projects??]
									<div class="ppSelect" style="width: auto;">
                                    <select  id="choosehistory"   name="projectId"  style="width: auto;padding: 0 18px;" >
                                        <option value="0" selected="selected" >选择已有</option>
										[#list projects as proj]
                                            <option  value="${proj.id!}"
                                                     attcnam="${proj.customerName!}"
                                                     attprov="${proj.areaProvince!}"
                                                     attprovn="${proj.provinceName!}"
                                                     attcity="${proj.areaCity!}"
                                                     attcityn="${proj.cityName!}"
                                            >
											${proj.projectName!}
                                            </option>
										[/#list]
                                    </select>
                                    </div>
								[#else]
									[#if !editor?? ]
                                    <input type="hidden" value=0 id="choosehistory" />
									[/#if]
								[/#if]

                                </div>
                                <div class="lableIterm">
                                    <label >甲方名称：</label>

                                    <input id="customerName" name="enqProject.customerName"
									[#if editor?? ]
									[#--编辑模式,该项不能改--]
                                           readonly="readonly"
									[/#if]
                                           value="${(enqmodel.enqProject.customerName)!}"  type="text" class="form-control" placeholder="只有您自己能查看，方便您后续查询项目及订单"/>

                                </div>
                                <div id="areawrap" class="lableIterm">
                                    <label ><span>*</span>项目所在地：</label>

                                    <input id="areacode" name="enqProject.areaProvince" value="${(enqmodel.enqProject.areaProvince)!}"    type="hidden"/>
                                    <input  id="areaname" name="enqProject.provinceName"  value="${(enqmodel.enqProject.provinceName)!}" type="hidden" />

                                    <input id="citycode"  name="enqProject.areaCity" value="${(enqmodel.enqProject.areaCity)!}"  type="hidden" >
                                    <input id="cityname"  name="enqProject.cityName"  value="${(enqmodel.enqProject.cityName)!}" type="hidden" >

                                    <input  id="areaProvince"  style="min-width: 220px;" value="${(enqmodel.enqProject.provinceName)!}[#if (enqmodel.enqProject.cityName)??]/${(enqmodel.enqProject.cityName)!}[/#if]"   placeholder="请选择省/市" class="form-control"  readonly />

                                </div>



					            <div class="lableIterm">
					                <label><span>*</span>联系人：</label>
					                    <input  name="contacts" data-rule="required;"
					                            [#if editor?? ]
					                            [#--编辑模式,取的地方不同--]
					                            value="${(enqmodel.contacts)!}"
					                            [#else]
					                                [#if (enqmodel.contacts)??]
					                                value="${(enqmodel.contacts)!}"
					                                [#else ]
													[#-- 联系人不再自动带入
														2017.3.20 联系人又要自动带入
					                                value="${(user.realName)!}"
													--]
                                                		value="${(user.realName)!}"
					                                [/#if]
					                            [/#if]
					                            type="text" class="form-control" placeholder="请填写项目联系人" />

					            </div>
								[#if user?? ]
					             <div class="lableIterm">
					                <label><span>*</span>联系电话：</label>
                                     <input id="myphone" name="phone" type="text" class="form-control contact" readonly
									 [#if user.mobile?? && user.mobile!="" ]
                                            value="${user.mobile!0}"
                                     onclick="tipShow()" onblur="tipHide()"/>
									  [#else]
                                          style="display: none;"
                                     />
									  <a  id="bindphone" onclick="bindPhone()" >请先绑定手机号</a>
									  [/#if]
									 <span id="phoneTip" style="text-align: left;"></span>
					           	 </div>
								[/#if]

					            <div class="lableIterm">
					                <label class="col-xs-2 control-label">QQ：</label>
					                    <input  name="qq" type="text" class="form-control" placeholder="请填写QQ号码"
					                        value="${(enqmodel.qq)!}"
					                    />

					            </div>
					             <div class="lableIterm">
					                <label class="col-xs-2 control-label">E-mail：</label>

					                    <input  data-rule="邮箱:email;"   name="email"
					                    [#if editor?? ]
					                    [#--编辑模式,取的地方不同--]
					                            value="${(enqmodel.email)!}"
					                    [#else]

					                            value="${(user.email)!}"
					                    [/#if]
					                             type="text" class="form-control contact" placeholder="请填写邮箱地址"/>

					            </div>
								</div>
							</div>
						</form>
                        <div class="confirmForm">
                            <button id="subtn" type="button" onclick="subform([#if editor??]true[#else]false[/#if])">确认发布</button>
                        	<button id="backButt" type="button" onclick="window.history.back()">返回</button>
                        </div>
						[#if !editor??]
							[@rule_content code="publish_lists"/]
						[/#if]
					</div>
				</div>
			</div>
		</div>
	</div>
    <div   id="successresult" class="faBuSuc"   >
        <div class="contTip"><img style="height: 40px;" src="/res/images/oparaStatus/aliveSuc_03.jpg" alt="">
            <div style="display: inline-block;vertical-align: top;margin-left:10px;"><h5>询价单提交成功</h5><h6 style="margin:10px 0 5px 0;">您发布的询价已提交，我们将在一个工作日内为您</h6><h6>
                完成审核，如比较紧急请致电：<strong style="color:#f9a32a;">400 848 1365</strong></h6><h6 style="margin-top: 10px;">您还可以 <a id="detailenq">查看刚发布的询价单</a> | <a id="managerenq" >管理询价单</a> | <a href="/enquiry/purchase/choose/" >继续发布询价单</a></h6></div>
        </div>
        <div style="text-align: center;margin-top: 30px;">
            <button class="iKnow" type="button" onclick="location.href=$('#detailenq').attr('href')">我知道了</button>
        </div>
    </div>

    <div style="width: 550px;bottom: 300px;background: white;z-index: 105;width: 570px;display:none;" id="toHand">
        <div style="margin-top: 50px;">
            <img alt="" src="/res/images/oparaStatus/warn.jpg" style="float: left;margin-left: 25px;">
            <h3 style="font-size: 18px;font-weight: bold;color: #333;margin: 0px;">您已经上传了清单文件</h3>
            <h6 style="font-size: 14px;color: #666;margin: 5px auto;margin-bottom: 0px;">切换到手动填写，您已经上传的询价清单将被清除，确认使用手工填写吗？</h6>
            <div style="width: 500px;margin-left:30px;margin-top: 30px;">
                <hr style="border: 1px solid #dddddd;">
                <h6 style="margin-top: 25px;width: 600px;">
                    <strong style="color:#00ccff;">温馨提示：</strong>如果上传的清单缺少需要询价的产品，请在原清单中添加缺少的产品后，重新上传。
                </h6>
            </div>
            <div style="margin-top: 30px;text-align: center;margin-bottom: 20px;">
                <button style="width: 95px;height: 35px;background: #00ccff;font-size: 16px;color: white;cursor: pointer;border: 1px solid #00ccff;margin-right: 20px;" onclick="toHandOp2(1)">确定</button>
                <button style="width: 95px;height: 35px;border: 1px solid #00ccff;font-size: 16px;color: #00ccff;cursor: pointer;background: white;" onclick="toHandOp2(0)">取消</button>
            </div>
        </div>
    </div>

    <div style="width: 530px;bottom: 300px;background: white;display:none;" id="toUp">
        <div style="margin-top: 50px;">
            <img alt="" src="/res/images/oparaStatus/warn.jpg" style="float: left;margin-left: 25px;">
            <h3 style="font-size: 18px;font-weight: bold;color: #333;margin: 0px;">您已经填写了询价清单</h3>
            <h6 style="font-size: 14px;color: #666;margin: 5px auto;margin-bottom: 0px;">切换到清单上传，您已手工填写的产品将被清除，确定使用清单上传吗? </h6>
            <div style="margin-top: 45px;text-align: center;margin-bottom: 20px;">
                <button style="width: 95px;height: 35px;background: #00ccff;font-size: 16px;color: white;cursor: pointer;border: 1px solid #00ccff;margin-right: 20px;" onclick="toUp2(1)">确定</button>
                <button style="width: 95px;height: 35px;border: 1px solid #00ccff;font-size: 16px;color: #00ccff;cursor: pointer;background: white;" onclick="toUp2(0)">取消</button>
            </div>
        </div>
    </div>


<script id="pici" type="text/html">
    <div class="fqpc">
    	<em class="ppSelect bfb fqs piciindex">第{{d.index}}期</em>
    	<input class="ppSelect bfb" name="pici"  placeholder="百分比" type="text"/>
    	<input class="ppSelect bz" name="beizhu" maxlength="50" placeholder="备注：如订金、货到两天内等（50字）" type="text"/>
    	<a style="vertical-align: middle;" onclick="cancleFq(this)">取消</a>
	</div>
</script>

<script src="/res/js/common/jquery.1.9.1.min.js"></script>
<script src="/res/js/common/common.js"></script>
<script src="/res/third/laydate/laydate.js"></script>
<script src="/res/third/layer/layer.js"></script>
<script src="/res/third/layer/layer.extends.js"></script>
<script src="/res/third/laytpl/laytpl.js"></script>
<script src="/res/third/nice-validator/jquery.validator.js?local=zh-CN"></script>
<script src="/res/third/city-picker/js/city-picker.data.js"></script>
<script src="/res/third/city-picker/js/city-picker.js"></script>
<style>
    .n-default .n-left, .n-default .n-right{
        margin-top:7px;
    }
    #phoneTip .n-right{
        margin-top:0px;
    }
    td.msgbox .msg-wrap{
		position: initial;
	}

    td.msgbox .msg-box.n-right{
        margin-top:0px;
	}
</style>
<script type="text/javascript">
function cityreset() {
	$("#areaProvince").citypicker({level:"city",simple:true,feedValBack:function (v) {
		$("#areaname").parent().find(".msg-box").remove();
	}});
}
[#if !(editor??) ]
cityreset();
[/#if]

/*上传区别对待*/
[#--上传--]  [#--重传--]
function uploadfile(){
	layer.fileManager(
			{initType:"file",
                suffixTypes:"xls,xlsx",
                fileSingleSizeLimit:5242880*2,
				"callback":function(data){
				upcallback(data);
			}}
	);
}

function uploadEnclosure(){
	layer.fileManager(
		{   initType:"file",
            suffixTypes:"doc,docx,xls,xlsx,ppt,pptx,zip,rar,gif,jpg,jpeg,bmp,png,pdf",
            fileSingleSizeLimit:5242880*2,
			"callback":function(data){
			attachfileback(data);
			}
		}
	);
}

//验证并且预先处理
$("#subform").validator({
    timely:2,
    focusCleanup:true,
    stopOnError:true,
    focusInvalid:true,
	rules:{
        v_excel:function (el, param, field) {
        	if($("#upbefore").is(":visible")){
                layer.msgShort("请上传询价清单");
				window.scrollTo(0,100);
                return "请上传询价单";
            }else{
                var excelpath = $("#excelpath").val();
				var itemvisible = $("#upbyhand").is(":visible");
                if(excelpath==null || excelpath ==""|| itemvisible ){//手动上架,编辑模式下,可能共同拥有excel与item
					var flag = true;
                    $(".input_1").each(function(){
                        var v = $(this).val().trim();
                        if(v==""){
                            layer.msgShort("商品名称不能为空!");
                            flag=false;
                            return false;
                        }
                    });

                    if(flag){
                        $(".input_4").each(function(){
                            var v = $(this).val().trim();
                            if(v==""){
                                layer.msgShort("单位不能为空!");
                                flag=false;
                                return false;
                            }
                        });
                    }

                    if(flag){
                        $(".input_5").each(function(){
                            var v = $(this).val().trim();
                            var re =/^[0-9]+.?[0-9]*$/;
                            if(!re.test(v)){
                                layer.msgShort("数量必填且必须为数字!");
                                flag=false;
                                return false;
                            }
                        });
                    }


                    if(flag){
                        $(".categoryPId").each(function () {
                            var v  = $(this).val();
                            if(v==""){
                                layer.msgShort("系统不能为空");
                                flag=false;
                                return false;
                            }
                        })
                    }


                    if(!flag){
                        window.scrollTo(0,100);
						return "询价单填写不完整"
					}
					return true;

                }
			}
        },
        v_city:function() {
			[#--项目所在地 ,选择已经有的项目就不需要判断了--]
            if($("#choosehistory").val()==0){
                var data = $("#areaProvince").data("citypicker");
                $("#areacode").val("");
                $("#areaname").val("");
                $("#citycode").val("");
                $("#cityname").val("");

                var getcode = data.getCode().trim();
                if(getcode==""){
                    layer.msgShort("请选择项目所在地");
                    var top = $("#areawrap").offset().top;
					window.scrollTo(0,top);
                    return "请选择项目所在地";
                }else{
                    var text = data.getVal();
                    if(getcode.indexOf("/")!=-1){
                        var codes = getcode.split("/");
                        var names = text.split("/");

                        $("#areacode").val(codes[0]);
                        $("#areaname").val(names[0]);

                        $("#citycode").val(codes[1]);
                        $("#cityname").val(names[1]);

                    }else{
                        $("#areacode").val(getcode);
                        $("#areaname").val(text);
                    }

                }
            }
            return true;
        },
        v_batchpay:function () {
        	var total =0;
			$("input[name='pici']").each(function (i) {
				var  t = $(this).val();
                total = total+parseInt(t);
            });

			if(total>100){
				return "分期比例总和不能超过100%"
			}

			return true;
        },
        v_phone:function (el, param, field) {
            var isPhone = /^([0-9]{3,4}[-_－—]?)?[0-9]{7,8}$/;
            //var isMob=/^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;
            var value=$("#myphone").val().trim();
            if(isPhone.test(value)){
                return true;
            }else{
                return "请先绑定手机号";
            }
        },
        v_ismyproject:function(el, param, field){
            var projectname =field.value;
            var msg =true;
            $.ajax({
                type:"post",
                url:"/enquiry/project/ismy",
                data:{projectname:projectname},
                dataType:"json",
                async:false,
                success:function(data){
                    if(!data.success){
                        msg=data.msg;
                    }
                }
            });

            return msg;
        }
	},
    fields: {
        enquiryName:"询价单名称:required;",
        excelvalid:{
            rule:"请上传询价单:required;v_excel; ",
            target:"#upbefore"
		},
        pici:{
			rule:"分期付款百分比:required(#fenpi:checked);integer(+);range(~100);v_batchpay",
			target:"#msgbox"
		},
        "enqProject.projectName":{
		    //2017.1.16 不能与自己发的项目重名
		    rule:"项目名称:required;v_ismyproject;",
            target:"#choosehistory"
        },
        "enqProject.provinceName":{
			rule:"v_city;",
			target:"#areawrap",
			must:true
		},
		phone:{
			must:true,
			target:"#phoneTip",
			rule:"v_phone;"
		}

    }
});


	[#--截止时间--]
    laydate({
        elem: '#endtime',
        min: laydate.now(),
        choose:function () {
			$("#endtime").focus();
        }
    });

	$("#handBody").on("mouseover mouseout",".del , .delActive" ,function(event){
        if(event.type == "mouseover"){
            $(this).removeClass("del").addClass("delActive");
        }else if(event.type == "mouseout"){
            $(this).removeClass("delActive").addClass("del");
        }
    });


    [#--上传回调--]
    function upcallback(response,params){
        if(response instanceof Array){
            response =response[0];
        }
        layer.closeAll();
        layer.msgShort("上传成功");
        var url = response.url;
        var name = response.name;
        $("#filename").html(name);
        $("#filename").attr("href",url);
        $("#excelName").val(name);
        chagestat(true,url);
    }
    [#--删除上传的--]
    function delurl(){
        chagestat(false,null);
    }


    [#--手动添加--]
    function addbyhand(){
    	//切换到手动添加,增加提示
		$("#upbyhand").show();
		$("#upbefore").hide();
	}

	/*删除所有*/
	function deleall(haswarn){
        var flag = checkShuru();
		if(flag && haswarn){
			layer.alert("确定全部删除?",function(){
                dealAllOk();
				layer.closeAll();
			})
		}else{
            dealAllOk();
		}
	}
/*确认全部删除*/
	function dealAllOk(){
        $("#upbyhand").hide();
        $("#upbefore").show();

        var size = $(".del").size();
        for(var i=size-1;i>=0;i--){
            removeTr($(".del").eq(i));
        }
	}

    function chagestat(b,url){
		if(b){
			$("#switchDiv").show();
			$("#upbefore").hide();
            $("#excelpath").val(url);
		}else{
            $("#switchDiv").hide();
            $("#upbefore").show();
            $("#excelpath").val("");
		}
	}

	[#--添加行--]
	function additem(){
        var ctr = $("#handBody").find("tr").last().clone(true);
        var indexnum = parseInt(ctr.attr("attindex"))+1;
        ctr.attr("attindex",indexnum);

        //序号
        ctr.find("td").eq(0).find("span").eq(0).text(indexnum+1);
        var ctrhtml = ctr.html();

        var abc = ctrhtml.replace(/items\[(\d+)\]/gm,"items["+indexnum+"]");
		//重置tr里的内容
        ctr.html(abc);

        ctr.find("input[class^='input_']").val("");

        $("#handBody").append(ctr);
	}


    //删除行
    function deletetr(obj){
        //询问框
        layer.confirm('是否清除该行？',function(){
            removeTr(obj);
            layer.msgShort("已清除");
        });
    }

    function removeTr(obj){
        var l = $("#handBody").find("tr").length;
        var _this = $(obj);
        var _parent = _this.parents("tr");
        if(l==1){
            _parent.find("input").each(function(i){
            	if(i>1){
                    $(this).val("");
				}
            })
        }else {
            var indexnum = parseInt(_parent.attr("attindex"));
            _parent.nextAll().each(function(){
                $(this).attr("attindex",indexnum);
                $(this).find("td").eq(0).find("span").eq(0).text(indexnum+1);
                $(this).html($(this).html().replace(/items\[(\d+)\]/gm,"items["+indexnum+"]"));
                indexnum++;
            });
            _parent.remove();
        }
    }

    [#--报价要求：--]
    $("#taxPrice").click(function(){
        if($(this).is(":checked")){
            $("#taxInstro").show();
        }else{
            $("#taxInstro").hide();
        }
    });

    [#--质保要求 其他--]
    $("input[name='quality']").click(function(){
        if($(this).val()==-1){
            $("#guaranteeinfo").show();
        }else {
            $("#guaranteeinfo").hide();
        }
    });


    [#--上传附件回调--]
    function attachfileback(response,params){
        if(response instanceof Array){
            response =response[0];
        }
        layer.closeAll();
        layer.msgShort("上传成功");
        var url = response.url;
        var name = response.name;
        $("#attachfile").val(url);
        $("#attachfileName").val(name);
        $("#attachfileNameTip").html(name);
        $("#attachfileNameTip").attr("href",url);
        $("#uploadattach").hide();
        $("#uploadattachfile").show()
    }

    [#--删除附件--]
    function delattachurl(){
        $("#uploadattach").show();
        $("#uploadattachfile").hide();
        $("#attachfile").val("");
        $("#attachfileName").val("");
    }


    function subform(iseditor){
        if($("#subform").isValid()){
            //分期付款比例
            var payment = $("input[name='payment']:checked").val();
            if(payment==3){
                var beizhu = $("input[name='beizhu']");
                var batchpay =[];
                $("input[name='pici']").each(function (i) {
                    var batch ={};
                    var b =  beizhu.eq(i).val();
                    var zhanbi = $(this).val();
                    batch.no = i;
                    batch.per= zhanbi;
                    batch.remark=b;
                    batchpay.push(batch);
                })
                $("#batchPay").val(JSON.stringify(batchpay));
            }else{
                $("#batchPay").val("");
            }
            var flag = true;
            if(flag){
                layer.post({
                    url:"/enquiry/purchase/create/save",
                    data:$("#subform").serialize(),
                    success:function(data){
                        if(data.success){
                            if(data.obj){
                                login();
                            }else{
                                var enqid = data.msg;
                                var ids = enqid.split("-");
                                $("#detailenq").attr("href","/enquiry/purchase/detail/"+ids[0]);
                                $("#managerenq").attr("href","/enquiry/project/detail/p/"+ids[1]+"/t/2");
                                layer.open({
                                    type: 1,
                                    title: false, //不显示标题
                                    maxWidth:500,
                                    content: $("#successresult"),
                                    cancel:function () {
										location.reload();
                                    }
                                });
                            }
                        }else{
                        	if(data.code==5 || data.code==3){
								layer.alert(data.msg,function () {
									window.open(data.obj);
                                })
							}else{
                                layer.msgShort(data.msg);
							}
						}
                    }
                },"保存中");
            }

        }
    }




    [#--选择已经有的--]
    $("#choosehistory").change(function(){
        if($(this).val()!=0){
            $("#choosenew").attr("novalidate",true).focus();
            $("#choosenew").hide();
            var opt = $(this).find("option:selected");
            $("#chhoseold").html(opt.text()).show();
            /*甲方名称*/
            var attcnam = opt.attr("attcnam");
            $("#customerName").val(attcnam).attr("readonly","readonly");
            /*项目所在地*/
            var attprovn = opt.attr("attprovn");
            var attcityn = opt.attr("attcityn");
            if(attcityn==""){
                $("#areaProvince").val(attprovn);
            }else{
                $("#areaProvince").val(attprovn+"/"+attcityn);
            }

            $("#areaProvince").citypicker('destroy');
            $("#createnew").show();
            $(this).parent().hide();
        };
    });

	/*创建该项目下的询价*/
	[#if projectId?? ]
		$("#choosehistory").val(${projectId}).change();
		$("#enquiryName").focus();
	[/#if]
    [#--创建新的项目--]
    $("#createnew").click(function(){
       // $("#areaProvince").citypicker('reset');
        cityreset();
        $(this).hide();
        $("#customerName").val("").removeAttr("readonly");
        $("#chhoseold").html("").hide();
        $("#choosenew").val("").show().removeAttr("novalidate");
        $("#choosehistory").val(0).parent().show();
    });


    function login(){
        layer.login("loginback");
    }

    function loginback(){
        location.reload();
    }


//选择器
var  $checkedobj =null;
function chooseService(obj){
    $checkedobj =$(obj);
    var current =$checkedobj.next().next().val();
	layer.category("/category/choose",{callback:"callback",current:current},obj);
}

function callback(name,id,atttop) {
    layer.closeAll();
    $checkedobj.text(name);
    $checkedobj.next().val(atttop).next().val(id);

}


/*判断有没有输入内容*/
function checkShuru(){
    var flag = false;
    var l = $(".ainput").each(function () {
        var v = $(this).val();
        if(v!=""){
            flag=true;
            return false;
        }
    });
	return flag;
}
/*手动切换到上传**/
function toUp(){
	var flag = checkShuru();
	if(flag){
        layer.open({
            type:1,
            title:false,
            area: ['530px', '253px'], //宽高
            content:$("#toUp")
        })
	}else{
		toUp2(1)
	}

}
function toUp2(type) {
    layer.closeAll();
	if(type==1){
        deleall(false);
	}
}


//切换手动
function toHandOp(){
    layer.open({
        type:1,
		title:false,
        area: ['635px', '293px'], //宽高
        content:$("#toHand")
    })
}
function toHandOp2(type) {
	layer.closeAll();
	if(type==1){
		$("#switchDiv").hide();
		$("#upbyhand").show();
	}
}
$("input[name='payment']").on("change",function () {
	if($(this).val()==3){
		$("#zhifufangshi").show();
	}else{
        $("#zhifufangshi").hide();
	}
})


//增加一个批次
function addpici() {
    var vtr = $(".fqOuter").find(".fqpc").size();
	if(vtr >= 6 ){
		layer.msgShort("最多分6期");
	}else{
        var t = $("#pici").html();
        laytpl(t).render({index:vtr+1}, function(html){
            $(".fqOuter").append(html);
        })
	}
}

//删除一个批次
function cancleFq(obj) {
	$(obj).parent().remove();
	//改批次
	$(".piciindex").each(function (i) {
		$(this).text("第"+(i+2)+"期");
    })
}
function bindPhone(){
	layer.bindPhone("bindcallback");
}
function bindcallback(mobile) {
    $("#myphone").val(mobile).show();
	$("#bindphone").hide();
	$("#phoneTip").empty();
    layer.closeAll();
}
function tipShow(){
	$("#phoneTip").text("抱歉，联系电话不可更改");
	$("#phoneTip").show();
}
function tipHide(){
	$("#phoneTip").text("");
	$("#phoneTip").hide();
}

function analysis() {
	var excelpath = $("#excelpath").val();
    window.open('/enquiry/before_mulity_retry?excelpath='+excelpath);
}
</script>
[#include "/front/common/front_foot.html"]
 	</body>
</html>
